package yhao.demo.aliyun.core;

import org.springframework.web.multipart.MultipartFile;
import yhao.infra.common.util.CommonStringUtil;

import java.util.UUID;

public class AliyunUploadRequest {
    //上传文件大小限制
    private long fileSizeLimit;
    //字节上传的文件流
    private byte[] fileByte;
    //字节上传的文件名称
    private String originalFileName;
    //文件类型
    private String fileType;
    //文件扩展名
    private String fileExtensionName;
    //上传后的文件名
    private String uploadFileName;
    public AliyunUploadRequest(MultipartFile file) {
        if(file == null){
            throw new IllegalArgumentException("文件上传对象不得为空");
        }
        try {
            this.fileByte = file.getBytes();
            this.originalFileName = file.getOriginalFilename();
            this.fileExtensionName = CommonStringUtil.getExtensionName(originalFileName);
            this.uploadFileName = UUID.randomUUID().toString() + "." + fileExtensionName;
            this.fileType = file.getContentType();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public long getFileSizeLimit() {
        return fileSizeLimit;
    }

    public void setFileSizeLimit(long fileSizeLimit) {
        this.fileSizeLimit = fileSizeLimit;
    }

    public byte[] getFileByte() {
        return fileByte;
    }

    public String getFileType() {
        return fileType;
    }

    public String getOriginalFileName() {
        return originalFileName;
    }

    public String getFileExtensionName() {
        return fileExtensionName;
    }

    public String getUploadFileName() {
        return uploadFileName;
    }

    public void setUploadFileName(String uploadFileName) {
        this.uploadFileName = uploadFileName;
    }
}
